/**
 * @version 2007-5-9
 * @author xalinx at gmail dot com
 */
package org.nanhill.commons.dbutil.dialect;


/**
 * @version 2007-5-9
 * @author xalinx at gmail dot com
 * 
 */
public class HsqlDialect extends Dialect {

	@Override
	public String getLimitSql(String sql, boolean hasOffset) {
		return new StringBuffer(sql.length() + 10).append(sql).insert(sql.toLowerCase().indexOf("select") + 6,
				hasOffset ? " limit ? ?" : " top ?").toString();
	}

	@Override
	public Object[] getLimitArguments(int start, int size, Object... args) {
		Object[] tmp = null;
		int len = args.length;
		if (start == 0) {
			tmp = new Object[len + 1];
			tmp[0] = size;
			System.arraycopy(args, 0, tmp, 1, args.length);
		} else {
			tmp = new Object[args.length + 2];
			tmp[0] = start;
			tmp[1] = size;
			System.arraycopy(args, 0, tmp, 2, args.length);
		}
		return tmp;
	}
	

}
